// Handle dialog
App.directive('edDialog', [function () {

    return {

        restrict: 'A',

        replace: true,

        transclude: true,

        template: '<div></div>',

        link: function (scope, elem, attrs, controller, transcludeFn) {

            var dialog = scope[attrs.edDialog] = {};

            transcludeFn(scope, function(cElement) {
                $(elem).append(cElement);
            });

            var option = AppUtil.jsonfy(attrs.options) || {};
            if (angular.isUndefined(option.autoOpen)) {
                option.autoOpen = false;
            }
            $(elem).dialog(option);

            // 设置title
            dialog.setTitle = function(title) {
                option.title = title;
                $(elem).dialog(option);
                return dialog;
            }

            // 显示
            dialog.show = function() {
                $(elem).dialog('open');
            }

            // 隐藏
            dialog.hide = function() {
                $(elem).dialog('close');
            }
        }

    };
}]);